home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / diropus4.12b_gpl / config / main8.c < prev    next >
C/C++ Source or Header  |  2000-01-27  |  12KB  |  405 lines

  1. /*
  2.  
  3. Directory Opus 4
  4. Original GPL release version 4.12
  5. Copyright 1993-2000 Jonathan Potter
  6.  
  7. This program is free software; you can redistribute it and/or
  8. modify it under the terms of the GNU General Public License
  9. as published by the Free Software Foundation; either version 2
  10. of the License, or (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  20.  
  21. All users of Directory Opus 4 (including versions distributed
  22. under the GPL) are entitled to upgrade to the latest version of
  23. Directory Opus version 5 at a reduced price. Please see
  24. http://www.gpsoft.com.au for more information.
  25.  
  26. The release of Directory Opus 4 under the GPL in NO WAY affects
  27. the existing commercial status of Directory Opus 5.
  28.  
  29. */
  30.  
  31. #include "config.h"
  32.  
  33. static struct DOpusRemember *hkey;
  34. static char **hotkeylist;
  35.  
  36. dohotkeysconfig()
  37. {
  38.     ULONG class;
  39.     USHORT code,gadgetid;
  40.     struct ConfigUndo *undo;
  41.     struct DOpusListView *view;
  42.     struct dopushotkey hotkey,*newhot,*hot,*swapfirst=NULL;
  43.     int a,mode=-1;
  44.  
  45.     showconfigscreen(CFG_HOTKEYS);
  46.     makehotkeylist();
  47.     undo=makeundo(UNDO_HOTKEYS);
  48.  
  49.     FOREVER {
  50.         Wait(1<<Window->UserPort->mp_SigBit);
  51.         while (IMsg=getintuimsg()) {
  52.             if ((view=ListViewIDCMP(&hotkeyslist,IMsg))==(struct DOpusListView *)-1) {
  53.                 class=IMsg->Class; code=IMsg->Code;
  54.                 if (class==GADGETUP || class==GADGETDOWN)
  55.                     gadgetid=((struct Gadget *)IMsg->IAddress)->GadgetID;
  56.                 ReplyMsg((struct Message *)IMsg);
  57.                 switch (class) {
  58.                     case MENUPICK:
  59.                         if (code==MENUNULL) break;
  60.                         if (mode>-1) {
  61.                             select_gadget(&maingad[mode],0);
  62.                             mode=-1;
  63.                         }
  64.                         dogadgetinfo(NULL);
  65.                         switch ((a=ITEMNUM(code))) {
  66.                             case 0:
  67.                             case 1:
  68.                                 if (doload(CFG_HOTKEYS,a)) {
  69.                                     makehotkeylist();
  70.                                     if (a) dogadgetinfo(cfg_string[STR_NEW_HOTKEYS_MERGED]);
  71.                                     else dogadgetinfo(cfg_string[STR_DEFAULT_HOTKEYS_MERGED]);
  72.                                 }
  73.                                 break;
  74.                         }
  75.                         break;
  76.                     case GADGETUP:
  77.                         if (gadgetid!=HOTKEYS_OKAY && gadgetid!=HOTKEYS_CANCEL) {
  78.                             if (mode==HOTKEYS_SWAP && swapfirst) {
  79.                                 swapfirst=NULL;
  80.                                 view->itemselected=-1;
  81.                                 makehotkeylist();
  82.                             }
  83.                             if (mode==gadgetid) {
  84.                                 mode=-1;
  85.                                 dogadgetinfo(NULL);
  86.                                 break;
  87.                             }
  88.                             if (mode>-1) {
  89.                                 select_gadget(&maingad[mode],0);
  90.                                 mode=-1;
  91.                             }
  92.                         }
  93.                         switch (gadgetid) {
  94.                             case HOTKEYS_OKAY:
  95.                             case HOTKEYS_CANCEL:
  96.                                 if (gadgetid==HOTKEYS_CANCEL) doundo(undo,UNDO_HOTKEYS);
  97.                                 doundo(undo,0);
  98.                                 RemoveListView(&hotkeyslist,1);
  99.                                 LFreeRemember(&hkey);
  100.                                 return((gadgetid==HOTKEYS_OKAY));
  101.                             case HOTKEYS_NEWHOTKEY:
  102.                                 hotkey.name[0]=0; hotkey.func.function=NULL;
  103.                                 hotkey.code=hotkey.qualifier=0;
  104.                                 hotkey.func.which=0;
  105.                                 hotkey.func.stack=4000;
  106.                                 hotkey.func.type=1; hotkey.func.pri=0;
  107.                                 hotkey.func.key=hotkey.func.qual=0;
  108.                                 hotkey.func.delay=2;
  109. editnewhotkey:
  110.                                 if (doedithotkey(&hotkey)) {
  111.                                     if (newhot=(struct dopushotkey *)
  112.                                         getcopy((char *)&hotkey,sizeof(struct dopushotkey),NULL)) {
  113.                                         newhot->func.function=getcopy(hotkey.func.function,-1,NULL);
  114.                                         hot=firsthotkey;
  115.                                         while (hot) {
  116.                                             if (!hot->next) break;
  117.                                             hot=hot->next;
  118.                                         }
  119.                                         if (hot) hot->next=newhot;
  120.                                         else firsthotkey=newhot;
  121.                                         newhot->next=NULL;
  122.                                     }
  123.                                 }
  124.                                 freefunction(&hotkey.func);
  125.                                 makehotkeylist();
  126.                                 break;
  127.                             case HOTKEYS_DELETE:
  128.                                 mode=HOTKEYS_DELETE;
  129.                                 dogadgetinfo(cfg_string[STR_SELECT_HOTKEY_TO_DELETE]);
  130.                                 break;
  131.                             case HOTKEYS_DUPLICATE:
  132.                                 mode=HOTKEYS_DUPLICATE;
  133.                                 dogadgetinfo(cfg_string[STR_SELECT_HOTKEY_TO_DUPLICATE]);
  134.                                 break;
  135.                             case HOTKEYS_SWAP:
  136.                                 mode=HOTKEYS_SWAP;
  137.                                 dogadgetinfo(cfg_string[STR_SELECT_HOTKEY_TO_SWAP]);
  138.                                 break;
  139.                         }
  140.                         break;
  141.                 }
  142.             }
  143.             else if (view) {
  144.                 if (view->itemselected>-1) {
  145.                     hot=firsthotkey;
  146.                     for (a=0;a<view->itemselected;a++,hot=hot->next) {
  147.                         if (!hot) break;
  148.                         newhot=hot;
  149.                     }
  150.                     if (hot) {
  151.                         switch (mode) {
  152.                             case -1:
  153.                                 view->itemselected=-1;
  154.                                 doedithotkey(hot);
  155.                                 makehotkeylist();
  156.                                 break;
  157.                             case HOTKEYS_DELETE:
  158.                                 if (request(cfg_string[STR_REALLY_DELETE_HOTKEY])) {
  159.                                     dogadgetinfo(cfg_string[STR_HOTKEY_DELETED]);
  160.                                     if (hot==firsthotkey) firsthotkey=firsthotkey->next;
  161.                                     else newhot->next=hot->next;
  162.                                     freefunction(&hot->func);
  163.                                     FreeMem(hot,sizeof(struct dopushotkey));
  164.                                 }
  165.                                 else dogadgetinfo(cfg_string[STR_SELECT_HOTKEY_TO_DELETE]);
  166.                                 makehotkeylist();
  167.                                 break;
  168.                             case HOTKEYS_DUPLICATE:
  169.                                 CopyMem((char *)hot,(char *)&hotkey,sizeof(struct dopushotkey));
  170.                                 hotkey.func.function=getcopy(hot->func.function,-1,NULL);
  171.                                 mode=-1;
  172.                                 goto editnewhotkey;
  173.                             case HOTKEYS_SWAP:
  174.                                 if (swapfirst) {
  175.                                     if (swapfirst!=hot)
  176.                                         SwapMem((char *)&swapfirst->code,
  177.                                             (char *)&hot->code,
  178.                                             sizeof(struct dopushotkey)-sizeof(struct dopushotkey *));
  179.                                     view->itemselected=-1;
  180.                                     makehotkeylist();
  181.                                     dogadgetinfo(cfg_string[STR_SELECT_HOTKEY_TO_SWAP]);
  182.                                     swapfirst=NULL;
  183.                                 }
  184.                                 else {
  185.                                     dogadgetinfo(cfg_string[STR_SELECT_SECOND_HOTKEY_TO_SWAP]);
  186.                                     swapfirst=hot;
  187.                                 }
  188.                                 break;
  189.                         }
  190.                     }
  191.                 }
  192.             }
  193.         }
  194.     }
  195. }
  196.  
  197. void makehotkeylist()
  198. {
  199.     struct dopushotkey *hotkey;
  200.     char *buf,str[40],name[40];
  201.     int a,count;
  202.  
  203.     LFreeRemember(&hkey); hotkeylist=NULL;
  204.     hotkey=firsthotkey;
  205.     for (count=0;;count++) {
  206.         if (!hotkey) break;
  207.         hotkey=hotkey->next;
  208.     }
  209.     if (count &&
  210.         (hotkeylist=LAllocRemember(&hkey,(count+1)*4,MEMF_CLEAR)) &&
  211.         (buf=LAllocRemember(&hkey,count*80,MEMF_CLEAR))) {
  212.         hotkey=firsthotkey;
  213.         for (a=0;a<count;a++) {
  214.             hotkeylist[a]=&buf[a*80];
  215.             RawkeyToStr(hotkey->code,hotkey->qualifier,str,NULL,39); str[39]=0;
  216.             strcpy(name,hotkey->name); name[36]=0;
  217.             lsprintf(hotkeylist[a],"%-36s %s",name,str);
  218.             hotkey=hotkey->next;
  219.         }
  220.     }
  221.     else hotkeylist=NULL;
  222.     hotkeyslist.items=hotkeylist; hotkeyslist.itemselected=-1;
  223.     RefreshListView(&hotkeyslist,1);
  224. }
  225.  
  226. doedithotkey(hotkey)
  227. struct dopushotkey *hotkey;
  228. {
  229.     int a;
  230.  
  231.     RemoveListView(&hotkeyslist,1);
  232.     cleanconfigscreen();
  233.     doscreentitle(cfg_string[STR_HOTKEY_EDIT_SCREEN]);
  234.     a=editfunction(&hotkey->func,CFG_HOTKEYS,hotkey);
  235.     showconfigscreen(CFG_HOTKEYS);
  236.     return(a);
  237. }
  238.  
  239. void drawcornerimage(r,x1,y1,bc,tc)
  240. struct RastPort *r;
  241. int x1,y1,bc,tc;
  242. {
  243.     SetAPen(r,screen_pens[0].pen);
  244.     RectFill(r,x1-5,y1-1,x1,y1+3);
  245.     SetDrMd(r,JAM1);
  246.     SetAPen(r,screen_pens[bc].pen);
  247.     BltTemplate((char *)pageflip_data1,0,2,r,x1-6,y1-1,6,5);
  248.     SetAPen(r,screen_pens[tc].pen);
  249.     BltTemplate((char *)pageflip_data2,0,2,r,x1-6,y1,6,3);
  250.     SetDrMd(r,JAM2);
  251. }
  252.  
  253. fixrmbimage(rmb,gad,on,x,y)
  254. struct RMBGadget *rmb;
  255. struct Gadget *gad;
  256. int on,x,y;
  257. {
  258.     int op,ret=0,a;
  259.     struct RMBGadget *rmbgad;
  260.  
  261.     op=rp->FgPen;
  262.     rmbgad=rmb;
  263.     while (rmbgad) {
  264.         rmbgad->high_bord[0]=gadget_unsel_border;
  265.         rmbgad->high_bord[1]=gadget_sel_border;
  266.         rmbgad->flags|=RGF_ALTBORD;
  267.         if (rmbgad->flags&RGF_ALTTEXT) {
  268.             for (a=0;a<2;a++) {
  269.                 rmbgad->txt[a].fg=screen_pens[1].pen;
  270.                 rmbgad->txt[a].bg=screen_pens[0].pen;
  271.             }
  272.         }
  273.         if (gad && on==2) {
  274.             rmbgad->x=gad->LeftEdge;
  275.             rmbgad->y=gad->TopEdge;
  276.         }
  277.         if (x==-1 ||
  278.             (x>=rmbgad->x && x<rmbgad->x+rmbgad->w &&
  279.             y>=rmbgad->y && y<rmbgad->y+rmbgad->h)) {
  280.             if (on)
  281.                 drawcornerimage(rp,rmbgad->x+rmbgad->w,rmbgad->y+1,config->gadgetbotcol,config->gadgettopcol);
  282.             else do3dbox(rmbgad->x+2,rmbgad->y+1,rmbgad->w-4,rmbgad->h-2);
  283.             ret=1;
  284.         }
  285.         rmbgad=rmbgad->next;
  286.         if (gad) {
  287.             gad->GadgetRender=gadget_dog_unsel_border;
  288.             gad->SelectRender=gadget_dog_sel_border;
  289.             gad->Flags|=GFLG_GADGHIMAGE;
  290.             gad->Flags&=~GFLG_GADGHCOMP;
  291.             if (rmbgad) {
  292.                 gad=gad->NextGadget;
  293.                 while (gad) {
  294.                     if (gad->LeftEdge==rmbgad->x && gad->TopEdge==rmbgad->y) break;
  295.                     gad=gad->NextGadget;
  296.                 }
  297.             }
  298.         }
  299.     }
  300.     SetAPen(rp,op);
  301.     return(ret);
  302. }
  303.  
  304. void doradiobuttons()
  305. {
  306.     int a;
  307.  
  308.     LFreeRemember(&buttonkey);
  309.  
  310.     buttonoffimage=
  311.         GetButtonImage(15,9,
  312.             screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,
  313.             screen_pens[0].pen,screen_pens[0].pen,&buttonkey);
  314.  
  315.     buttononimage=
  316.         GetButtonImage(15,9,
  317.             screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen,
  318.             screen_pens[3].pen,screen_pens[0].pen,&buttonkey);
  319.  
  320.     if (checkoffimage=
  321.         GetCheckImage(screen_pens[1].pen,screen_pens[0].pen,0,&buttonkey))
  322.         CopyMem((char *)checkoffimage,(char *)©_checkoffimage,sizeof(struct Image));
  323.     else copy_checkoffimage.ImageData=NULL;
  324.  
  325.     if (checkonimage=
  326.         GetCheckImage(screen_pens[1].pen,screen_pens[0].pen,1,&buttonkey))
  327.         CopyMem((char *)checkonimage,(char *)©_checkonimage,sizeof(struct Image));
  328.     else copy_checkonimage.ImageData=NULL;
  329.  
  330.     stringex.Pens[0]=screen_pens[config->stringfgcol].pen;
  331.     stringex.Pens[1]=screen_pens[config->stringbgcol].pen;
  332.     stringex.ActivePens[0]=screen_pens[config->stringselfgcol].pen;
  333.     stringex.ActivePens[1]=screen_pens[config->stringselbgcol].pen;
  334.  
  335.     CreateGadgetBorders(&buttonkey,
  336.         104,12,
  337.         &gadget_dog_sel_border,&gadget_dog_unsel_border,
  338.         1,
  339.         screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  340.  
  341.     CreateGadgetBorders(&buttonkey,
  342.         104,12,
  343.         &gadget_sel_border,&gadget_unsel_border,
  344.         0,
  345.         screen_pens[config->gadgettopcol].pen,screen_pens[config->gadgetbotcol].pen);
  346.  
  347.     fix_gadget_border(&cmdcancelgad);
  348.     fix_gadget_border(&helpcancelgad);
  349.     for (a=0;a<3;a++) fix_gadget_border(&listokaygad[a]);
  350. }
  351.  
  352. void fix_gadget_border(gad)
  353. struct Gadget *gad;
  354. {
  355.     gad->Flags=(gadget_sel_border)?GFLG_GADGHIMAGE:GFLG_GADGHCOMP;
  356.     gad->GadgetRender=gadget_unsel_border;
  357.     gad->SelectRender=gadget_sel_border;
  358. }
  359.  
  360. void select_gadget(gad,state)
  361. struct Gadget *gad;
  362. int state;
  363. {
  364.     if ((state && !gad->SelectRender) || (!state && !gad->GadgetRender))
  365.         HiliteGad(gad,rp);
  366.     else {
  367.         if (state) DrawBorder(rp,gad->SelectRender,gad->LeftEdge,gad->TopEdge);
  368.         else DrawBorder(rp,gad->GadgetRender,gad->LeftEdge,gad->TopEdge);
  369.     }
  370.     if (gad->Activation&GACT_TOGGLESELECT) {
  371.         if (state) gad->Flags|=GFLG_SELECTED;
  372.         else gad->Flags&=~GFLG_SELECTED;
  373.     }
  374. }
  375.  
  376. void fix_gadget_positions()
  377. {
  378.     int a;
  379.  
  380.     for (a=0;a<3;a++) fix_gad_pos(&menuslidergads[a],menuslidergads_xy[a]);
  381.     for (a=0;a<4;a++) {
  382.         fix_gad_pos(&editdrivegadgets[a],editdrivegadgets_xy[a]);
  383.         fix_gad_pos(&icongads[a],icongads_xy[a]);
  384.     }
  385.     for (a=0;a<6;a++) fix_gad_pos(&palettegads[a],palettegads_xy[a]);
  386.     for (a=0;a<7;a++) fix_gad_pos(&screenmodegads[a],screenmodegads_xy[a]);
  387.     for (a=0;a<8;a++) fix_gad_pos(&arrowgadgets[a],arrowgadgets_xy[a]);
  388.     for (a=0;a<10;a++) fix_gad_pos(&formatgads[a],formatgads_xy[a]);
  389.     for (a=0;a<14;a++) fix_gad_pos(&editclassgadgets[a],editclassgadgets_xy[a]);
  390.     for (a=0;a<15;a++) fix_gad_pos(&editfuncgadgets[a],editfuncgadgets_xy[a]);
  391.     fix_gad_pos(&coloursgad,coloursgad_xy);
  392.     fix_gad_pos(&hotkeymmbgad,hotkeymmbgad_xy);
  393.     fix_gad_pos(&hotkeygad,hotkeygad_xy);
  394.     fix_gad_pos(&fontsizegadget,fontsizegadget_xy);
  395.     for (a=0;a<2;a++) fix_gad_pos(&screen_sliders_gadgets[a],screen_sliders_gadgets_xy[a]);
  396. }
  397.  
  398. void fix_gad_pos(gad,pos)
  399. struct Gadget *gad;
  400. short *pos;
  401. {
  402.     gad->LeftEdge=x_off+pos[0];
  403.     gad->TopEdge=y_off+pos[1];
  404. }
  405.